/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.ban.data.exchange.runner.tokenBucket.util;

import java.util.Collection;
import java.util.HashSet;

/**
 *
 * @author zwlin
 */
public class ServiceInfo {

    private final Collection<String> hosts;
    private final String suffix;
    private String prefix = "http://";

    public ServiceInfo(Collection<String> hosts, String suffix) {
        this.hosts = hosts;
        if (suffix.startsWith("/")) {
        } else {
            suffix = "/" + suffix;
        }
        this.suffix = suffix;
    }

    public ServiceInfo(Collection<String> ips, int port, String suffix) {
        this.hosts = new HashSet<>();
        ips.forEach((ip) -> {
            this.hosts.add(ip + ":" + port);
        });
        if (suffix.startsWith("/")) {
        } else {
            suffix = "/" + suffix;
        }
        this.suffix = suffix;
    }

    public Collection<String> getHosts() {
        return hosts;
    }

    public String getSuffix() {
        return suffix;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public Collection<String> getUrls() {
        HashSet<String> urls = new HashSet<>();
        hosts.forEach((host) -> {
            urls.add(prefix + host + suffix);
        });
        return urls;
    }
}
